<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>房贷综合计算器</title>
    <style>
        * {
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4edf9 100%);
            padding: 15px;
            min-height: 100vh;
            margin: 0;
            color: #333;
        }
        .calculator-container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(90deg, #1a5fb4 0%, #2a7cc7 100%);
            color: white;
            padding: 20px;
            text-align: center;
        }
        .header h1 {
            margin: 0;
            font-size: 22px;
            font-weight: 600;
        }
        .input-section {
            padding: 20px;
            border-bottom: 1px solid #eaeef5;
        }
        .input-group {
            display: flex;
            margin-bottom: 15px;
            align-items: center;
        }
        .input-group label {
            flex: 0 0 40%;
            font-weight: 500;
            font-size: 15px;
        }
        .input-group input {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid #d1d9e6;
            border-radius: 6px;
            font-size: 15px;
            transition: border-color 0.3s;
        }
        .input-group input:focus {
            outline: none;
            border-color: #1a5fb4;
            box-shadow: 0 0 0 2px rgba(26, 95, 180, 0.2);
        }
        .calculate-btn {
            background: linear-gradient(90deg, #1a5fb4 0%, #2a7cc7 100%);
            color: white;
            border: none;
            padding: 12px;
            width: 100%;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 10px rgba(26, 95, 180, 0.3);
        }
        .calculate-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 15px rgba(26, 95, 180, 0.4);
        }
        .results-section {
            padding: 0 20px 20px;
        }
        .results-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            margin-top: 15px;
        }
        .result-card {
            background: #f8fafd;
            border-radius: 8px;
            padding: 15px;
            border-left: 4px solid #1a5fb4;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }
        .result-title {
            font-size: 13px;
            color: #5a7a9c;
            margin-bottom: 6px;
            font-weight: 500;
        }
        .result-value {
            font-size: 18px;
            font-weight: 600;
            color: #1a5fb4;
        }
        .result-unit {
            font-size: 12px;
            color: #7d95b3;
            margin-left: 3px;
        }
        .monthly-payment {
            grid-column: span 2;
            background: linear-gradient(90deg, #f8fafd 0%, #e9f2fc 100%);
            border-left: 4px solid #ff9800;
            padding: 12px 15px;
        }
        .monthly-payment .result-title {
            color: #ff9800;
        }
        .monthly-payment .result-value {
            color: #ff6d00;
        }
        .calculation-details {
            background: #f0f7ff;
            border-radius: 8px;
            padding: 15px;
            margin-top: 20px;
            font-size: 13px;
            color: #5a7a9c;
            border-left: 4px solid #4fc3f7;
        }
        .detail-title {
            font-weight: 600;
            margin-bottom: 8px;
            color: #1a5fb4;
        }
        .detail-item {
            margin-bottom: 6px;
        }
        .footer {
            text-align: center;
            padding: 15px;
            color: #7d95b3;
            font-size: 12px;
            background: #f8fafd;
            border-top: 1px solid #eaeef5;
        }
        @media (max-width: 600px) {
            .results-grid {
                grid-template-columns: 1fr;
                gap: 10px;
            }
            .monthly-payment {
                grid-column: span 1;
            }
            .input-group {
                flex-direction: column;
                align-items: flex-start;
            }
            .input-group label {
                margin-bottom: 8px;
                flex: 0 0 100%;
            }
            .result-card {
                padding: 12px;
            }
            .monthly-payment {
                padding: 12px;
            }
            .results-section {
                padding: 0 15px 15px;
            }
        }
    </style>
</head>
<body>
    <div class="calculator-container">
        <div class="header">
            <h1>房贷综合计算器</h1>
        </div>
        
        <div class="input-section">
            <div class="input-group">
                <label for="housePrice">房屋总价（万元）:</label>
                <input type="number" id="housePrice" placeholder="请输入房屋总价" min="0" step="0.1">
            </div>
            <button class="calculate-btn" onclick="calculateMortgage()">计算房贷信息</button>
        </div>
        
        <div class="results-section">
            <div class="results-grid">
                <div class="result-card">
                    <div class="result-title">房屋首付款</div>
                    <div class="result-value" id="downPayment">0.00</div>
                    <span class="result-unit">万元</span>
                </div>
                
                <div class="result-card">
                    <div class="result-title">房屋契税</div>
                    <div class="result-value" id="propertyTax">0.00</div>
                    <span class="result-unit">万元</span>
                </div>
                
                <div class="result-card">
                    <div class="result-title">房屋中介费</div>
                    <div class="result-value" id="agentFee">0.00</div>
                    <span class="result-unit">万元</span>
                </div>
                
                <div class="result-card">
                    <div class="result-title">公积金贷款总额</div>
                    <div class="result-value" id="providentFundLoan">130.00</div>
                    <span class="result-unit">万元</span>
                </div>
                
                <div class="result-card">
                    <div class="result-title">商业贷款总额</div>
                    <div class="result-value" id="commercialLoan">0.00</div>
                    <span class="result-unit">万元</span>
                </div>
                
                <div class="result-card monthly-payment">
                    <div class="result-title">公积金月供金额（首月）</div>
                    <div class="result-value" id="providentFundPayment">0.00</div>
                    <span class="result-unit">元</span>
                </div>
                
                <div class="result-card monthly-payment">
                    <div class="result-title">商业月供金额（首月）</div>
                    <div class="result-value" id="commercialPayment">0.00</div>
                    <span class="result-unit">元</span>
                </div>
            </div>
            
            <div class="calculation-details">
                <div class="detail-title">计算说明：</div>
                <div class="detail-item">1. 房屋首付款 = 房屋总价 × 20%</div>
                <div class="detail-item">2. 房屋契税 = 房屋总价 × 1%</div>
                <div class="detail-item">3. 房屋中介费 = 房屋总价 × 2%</div>
                <div class="detail-item">4. 公积金贷款总额固定为130万元</div>
                <div class="detail-item">5. 商业贷款总额 = 房屋总价 - 首付款 - 公积金贷款</div>
                <div class="detail-item">6. 公积金月供（首月）按等额本金方式计算：贷款30年，利率2.85%</div>
                <div class="detail-item">7. 商业月供（首月）按等额本金方式计算：贷款30年，利率3.05%</div>
            </div>
        </div>
        
        <div class="footer">
            注：计算结果仅供参考，实际费用请咨询相关金融机构
        </div>
    </div>

    <script>
        function calculateMortgage() {
            // 获取输入值
            const housePrice = parseFloat(document.getElementById('housePrice').value);
            
            if (isNaN(housePrice) || housePrice <= 0) {
                alert("请输入有效的房屋总价（大于0的数字）");
                return;
            }
            
            // 计算各项费用
            const downPayment = housePrice * 0.2; // 首付20%
            const propertyTax = housePrice * 0.01; // 契税1%
            const agentFee = housePrice * 0.02; // 中介费2%
            const providentFundLoan = 130; // 公积金贷款固定130万
            
            // 商业贷款总额
            const commercialLoan = housePrice - downPayment - providentFundLoan;
            
            // 计算公积金月供（等额本金，首月）
            const providentFundRate = 2.85 / 100 / 12; // 月利率
            const providentFundMonths = 30 * 12; // 贷款期数
            const providentFundMonthlyPrincipal = providentFundLoan * 10000 / providentFundMonths;
            const providentFundFirstMonthInterest = providentFundLoan * 10000 * providentFundRate;
            const providentFundPayment = providentFundMonthlyPrincipal + providentFundFirstMonthInterest;
            
            // 计算商业月供（等额本金，首月）
            const commercialLoanRate = 3.05 / 100 / 12; // 月利率
            const commercialLoanMonths = 30 * 12; // 贷款期数
            let commercialPayment = 0;
            if (commercialLoan > 0) {
                const commercialMonthlyPrincipal = commercialLoan * 10000 / commercialLoanMonths;
                const commercialFirstMonthInterest = commercialLoan * 10000 * commercialLoanRate;
                commercialPayment = commercialMonthlyPrincipal + commercialFirstMonthInterest;
            }
            
            // 更新页面显示
            document.getElementById('downPayment').textContent = downPayment.toFixed(2);
            document.getElementById('propertyTax').textContent = propertyTax.toFixed(2);
            document.getElementById('agentFee').textContent = agentFee.toFixed(2);
            document.getElementById('providentFundLoan').textContent = providentFundLoan.toFixed(2);
            document.getElementById('commercialLoan').textContent = commercialLoan > 0 ? commercialLoan.toFixed(2) : "0.00";
            document.getElementById('providentFundPayment').textContent = providentFundPayment.toFixed(2);
            document.getElementById('commercialPayment').textContent = commercialLoan > 0 ? commercialPayment.toFixed(2) : "0.00";
        }
        
        // 初始计算示例
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('housePrice').value = "300";
            calculateMortgage();
        });
    </script>
</body>
</html>